package homework.day02;

import java.io.*;
import java.util.Arrays;
import java.util.Map;

/**
 * 将当前项目目录下的所有.txt文件复制一份。
 * 复制文件的名字格式:原文件名_cp.txt
 * 例如:
 * 复制当前项目目录下的demo.txt时，复制的文件名为demo_cp.txt
 *
 */
public class Test04 {
    public static void main(String[] args) throws Exception {
        File file = new File(".");
        File [] sub = file.listFiles(f->f.getName().endsWith(".txt"));
        System.out.println(Arrays.toString(sub));
        byte [] bytes = new byte[1024*100];
        for (File subs:sub) {
            String [] st = subs.getName().split("\\.");
            FileInputStream fis = new FileInputStream(subs);
            FileOutputStream fos = new FileOutputStream(st[0]+"_cp.txt");
            int len ;
            while ((len=fis.read(bytes))!=-1){
                fos.write(bytes,0,len);
            }
        }
    }
}
